package com.zjuee.web.ledger.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zjuee.base.constant.DictionaryConstants;
import com.zjuee.base.dto.common.login.LoginDto;
import com.zjuee.base.exception.ServiceException;
import com.zjuee.base.dto.common.ledger.LedgerProduceApprovalDto;
import com.zjuee.base.model.common.ledger.LedgerProduceApproval;
import com.zjuee.base.model.common.ledger.LedgerProduceGather;
import com.zjuee.service.LedgerProduceApprovalService;
import com.zjuee.web.ledger.mapper.LedgerProduceApprovalMapper;
import com.zjuee.web.ledger.mapper.LedgerProduceBillMapper;
import com.zjuee.web.ledger.mapper.LedgerProduceGatherMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author wu liang
 * @since 1.0
 */
@Slf4j
@Service
public class LedgerProduceApprovalServiceImpl implements LedgerProduceApprovalService {

    @Resource
    private LedgerProduceGatherMapper ledgerProduceGatherMapper;
    @Resource
    private LedgerProduceBillMapper ledgerProduceBillMapper;
    @Resource
    private LedgerProduceApprovalMapper ledgerProduceApprovalMapper;
    @Resource
    LoginDto loginDto;

    @Override
    @Transactional
    public Long add(LedgerProduceApproval type) {
        Long wlpgId = type.getWlpgId();
        //查询台账汇总信息
        LedgerProduceGather ledgerProduceGather = ledgerProduceGatherMapper.selectById(wlpgId);
        if (ledgerProduceGather == null) {
            throw new ServiceException("产生台账信息不能为空!");
        }
        //台账变更信息插入
        type.setWlpaAuditStatus(DictionaryConstants.WL_AUDIT_STATUS_UNAUDIT);
        type.setWlpaCreateTime(new Date());
        type.setWlpaCreator(loginDto.getUserName());
        ledgerProduceApprovalMapper.insert(type);

        //更新台账汇总数据
        ledgerProduceGather.setWlpgModifiedTime(new Date());
        ledgerProduceGather.setWlpgModifier(loginDto.getUserName());
        ledgerProduceGather.setWlpgCanEdit(DictionaryConstants.WL_EDIT_STATUS_ING);
        ledgerProduceGatherMapper.updateById(ledgerProduceGather);

        return 1l;
    }

    @Override
    public boolean delete(Long id, Long validateId) {
        return false;
    }

    @Override
    public boolean update(LedgerProduceApproval type) {
        return false;
    }

    @Override
    public LedgerProduceApproval selectById(Long id, Long validateId) {
        return null;
    }

    @Override
    public Page<LedgerProduceApproval> list(LedgerProduceApprovalDto dto) {
        return null;
    }

    @Override
    public LambdaQueryWrapper<LedgerProduceApproval> fuzzyQuery(LedgerProduceApprovalDto dto) {
        return null;
    }
}
